package com.hj.javase.classspath;

import java.io.*;

/**
 * @Author : hujing
 * @Date: 2025/6/19 16:03
 * @Description:
 */
public class ReadClassPathSource {

    public static void main(String[] args) {
        // 读取类路径下的文件,在classpath中的资源文件，路径总是以／开头
        InputStream is = ReadClassPathSource.class.getResourceAsStream("/笔记.txt");
        if (is != null) {
            // 按行读取文件内容
            try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
                String line;
                while ((line = br.readLine()) != null) {
                    System.out.println(line);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
